/**
 * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.opsli.modulars.business.patrolStation.web;

import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.opsli.api.web.business.patrolStation.PatrolStationRestApi;
import org.opsli.api.wrapper.business.emergency.EmergencyReportModel;
import org.opsli.api.wrapper.business.patrolLocation.PatrolLocationModel;
import org.opsli.api.wrapper.business.patrolStation.PatrolStationModel;
import org.opsli.api.wrapper.system.org.SysOrgModel;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.common.annotation.RequiresPermissionsCus;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog;
import org.opsli.core.base.controller.BaseRestController;
import org.opsli.core.persistence.Page;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.persistence.querybuilder.WebQueryBuilder;
import org.opsli.core.utils.GpsCoordinateUtils;
import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.business.analysisExcel.web.ReadExcelUtils;
import org.opsli.modulars.business.app.web.CoordinatesConvertUtil;
import org.opsli.modulars.business.app.web.MapCordinatesVo;
import org.opsli.modulars.business.app.web.ZkUtils;
import org.opsli.modulars.business.patrolDict.entity.PatrolDict;
import org.opsli.modulars.business.patrolDict.service.IPatrolDictService;
import org.opsli.modulars.business.patrolStation.entity.PatrolStationWeb;
import org.opsli.modulars.business.pipelineStation.entity.PipelineStation;
import org.opsli.modulars.business.route.entity.Route;
import org.opsli.modulars.business.route.service.IRouteService;
import org.opsli.modulars.business.routeStation.entity.RouteStation;
import org.opsli.modulars.business.routeStation.service.IRouteStationService;
import org.opsli.modulars.business.routeStation.service.impl.RouteStationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
import java.util.*;

import org.opsli.modulars.business.patrolStation.entity.PatrolStation;
import org.opsli.modulars.business.patrolStation.service.IPatrolStationService;

/**
 * 巡点管理 Controller
 *
 * @author zk
 * @date 2021-09-14 15:53:53
 */
@Api(tags = PatrolStationRestApi.TITLE)
@Slf4j
@ApiRestController("/business/patrolStation")
public class PatrolStationRestController extends BaseRestController<PatrolStation, PatrolStationModel, IPatrolStationService>
    implements PatrolStationRestApi {

    @Value("${opsli.fileUrl}")
    private  String fileUrl;
    @Autowired
    private IPatrolDictService dictService;
    @Autowired
    private IRouteService routeService;
    @Autowired
    private IRouteStationService routeStationService;

    public  String nameList;
    /**
    * 巡点管理 查一条
    * @param model 模型
    * @return ResultVo
    */
    @ApiOperation(value = "获得单条巡点管理", notes = "获得单条巡点管理 - ID")
   /* @RequiresPermissions("patrolstation_select")*/
    @Override
    public ResultVo<PatrolStationModel> get(PatrolStationModel model) {
        // 如果系统内部调用 则直接查数据库
        if(model != null && model.getIzApi() != null && model.getIzApi()){
            model = IService.get(model);
        }
        return ResultVo.success(model);
    }

    @Override
    public ResultVo<Map> getOne() {
        Map map=new HashMap();
        String devid=UserUtil.getSysUser().getCompanyId();
        if(devid.equals("41002")){
            map.put("ad","新华正街");
            map.put("city","浠水县");
            map.put("ln","115.273178");
            map.put("lt","30.457733");
        }else{
            map.put("ad","上街天伦燃气");
            map.put("city","郑州市");
            map.put("ln","113.326973");
            map.put("lt","34.817928");
        }
        return ResultVo.success(map);
    }

    @Autowired
    RouteStationServiceImpl rs;

    @Override
    public ResultVo<Map> getList() {
        Map datamap=new HashMap();
        String devid=UserUtil.getSysUser().getCompanyId();
        SysOrgModel smodel=UserUtil.getOrg(devid);
        datamap.put("lt",smodel.getLt());
        datamap.put("ln",smodel.getLn());
        List<PatrolStationModel> list=IService.findListFm(devid);
        List<Map> maps=new ArrayList<>();
        PatrolDict dict=dictService.findLast(devid);
        if(list!=null&&list.size()>0&&dict.getSstate().equals("1")) {
            for (PatrolStationModel model : list) {
                Map map = new HashMap();
                try {
                    MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                    cordinatesVo.setLon(new BigDecimal(model.getLongitude()));
                    cordinatesVo.setLat(new BigDecimal(model.getDimension()));
                    cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                    map.put("stationName", model.getStationName());
                    map.put("longitude", cordinatesVo.getLon());
                    map.put("dimension",cordinatesVo.getLat());
                    map.put("location", model.getLocation());
                    map.put("userName", model.getUserName());
                    map.put("lastTime", model.getLastTime());
                    map.put("lastPic", model.getLastPic());
                    map.put("description", model.getDescription());
                    map.put("id", model.getId());
                    map.put("sType", model.getType());
                    map.put("type", 1);
                    maps.add(map);
                }catch (Exception e){
                    System.out.println("坐标转换异常="+JSON.toJSONString(model));
                }

            }
        }
        List<EmergencyReportModel> elist=IService.findEList(devid);
        if(elist!=null&&elist.size()>0&&dict.getEstate().equals("1")) {
            for (EmergencyReportModel model : elist) {
                Map map = new HashMap();
                MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                cordinatesVo.setLon(new BigDecimal(model.getLongitude()));
                cordinatesVo.setLat(new BigDecimal(model.getDimension()));
                cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                map.put("longitude", cordinatesVo.getLon());
                map.put("dimension", cordinatesVo.getLat());
                map.put("location", model.getLocation());
                map.put("userName", model.getUserName());
                map.put("emergencyTitle", model.getEmergencyTitle());
                map.put("reportTime", model.getReportTime());
                map.put("reportPic", model.getReportPic());
                map.put("description", model.getDescription());
                map.put("id", model.getId());
                map.put("type", 2);
                maps.add(map);
            }
        }
        List<PatrolLocationModel> plist=IService.findPList(devid);
        if(plist!=null&&plist.size()>0&&dict.getPstate().equals("1")) {
            for (PatrolLocationModel model : plist) {
                Map map = new HashMap();
                MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                cordinatesVo.setLon(new BigDecimal(model.getLongitude()));
                cordinatesVo.setLat(new BigDecimal(model.getDimension()));
                cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                map.put("longitude", cordinatesVo.getLon());
                map.put("dimension", cordinatesVo.getLat());
                map.put("location", model.getLocation());
                map.put("userName", model.getUserName());
                map.put("lastTime", model.getLastTime());
                map.put("userId", model.getUserId());
                map.put("type", 3);
                maps.add(map);
            }
        }
        datamap.put("list",maps);
        Route route=new Route();
        route.setDevid(devid);
        List<Route> models =routeService.getList(route);
        List<Map> rlist=new ArrayList<Map>();
        if(models!=null&&models.size()>0&&dict.getRstate().equals("1")){
            for(Route model:models){
                Map rmap=new HashMap();
                rmap.put("name",model.getRouteName());
                rmap.put("id",model.getId());
                List<RouteStation> stations=routeStationService.findList(model.getId());
                if(stations!=null&&stations.size()>0) {
                    for(RouteStation station:stations){
                        MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                        cordinatesVo.setLon(new BigDecimal(station.getLongitude()));
                        cordinatesVo.setLat(new BigDecimal(station.getDimension()));
                        cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                        station.setLongitude(cordinatesVo.getLon().toString());
                        station.setDimension(cordinatesVo.getLat().toString());
                    }
                    rmap.put("value",stations);
                    rmap.put("type",1);
                    rlist.add(rmap);
                }
            }
        }
        datamap.put("rlist",rlist);

        List listd = new ArrayList();
        if (devid.equals("41006")) {
            String routeId = null;
            if(models!=null&&models.size()>0&&dict.getRstate().equals("1")){
                for(Route model:models){
                    routeId = model.getId();
                }
            }
            Map map = new HashMap();
            map.put("devid", devid);
            listd.add(map);
            List l2 = new ArrayList();
            List<RouteStation> l = rs.findAnZeList(routeId);
            for (int i = 0; i < l.size(); i++) {
                Map m = new HashMap();
                RouteStation r = l.get(i);
                String longitude = r.getLongitude();
                String dimension = r.getDimension();
                m.put("lt", longitude);
                m.put("ln", dimension);
                l2.add(m);
                if (longitude.equals("0") && dimension.equals("0")) {
                    List l3 = new ArrayList();
                    for (int a = 0; a < l2.size() - 1; a++) {
                        l3.add(l2.get(a));
                    }
                    listd.add(l3);
                    l2.clear();
                }
            }
        }
        datamap.put("localroute", listd);

        return ResultVo.success(datamap);
    }

    @Override
    public ResultVo<Map> getListHome() {
        Map datamap=new HashMap();
        String devid=UserUtil.getSysUser().getCompanyId();
        SysOrgModel smodel=UserUtil.getOrg(devid);
        datamap.put("lt",smodel.getLt());
        datamap.put("ln",smodel.getLn());

        List<Map> maps=new ArrayList<>();

        List<PatrolLocationModel> plist=IService.findPListHome(devid);
        if(plist!=null&&plist.size()>0) {
            for (PatrolLocationModel model : plist) {
                Map map = new HashMap();
                MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                cordinatesVo.setLon(new BigDecimal(model.getLongitude()));
                cordinatesVo.setLat(new BigDecimal(model.getDimension()));
                cordinatesVo= CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                map.put("longitude", cordinatesVo.getLon());
                map.put("dimension", cordinatesVo.getLat());
                map.put("location", model.getLocation());
                map.put("userName", model.getUserName());
                map.put("lastTime", model.getLastTime());
                map.put("userId", model.getUserId());
                map.put("type", 3);
                maps.add(map);
            }
        }
        datamap.put("list",maps);


        return ResultVo.success(datamap);
    }


    @Override
    public ResultVo<Map> getFile(String id){
        Map map=new HashMap();
        PatrolStationModel model=IService.get(id);
        List<Map> list=new ArrayList<Map>();
        if(ZkUtils.isNotBlank(model.getLastPic())){
            String[] arr=model.getLastPic().split(",");
            for(String s:arr){
                Map datamap=new HashMap();
                datamap.put("src",fileUrl+s);
                list.add(datamap);
            }
        }
        map.put("pic",list);
        if(ZkUtils.isNotBlank(model.getLastVideo())){
            map.put("video", fileUrl+model.getLastVideo());
        }else{
            map.put("video", "");
        }
        return ResultVo.success(map);}

    @Override
    public ResultVo<List<Map>> findLast(String xdId) {
        List<Map> mapList = new ArrayList();
        List<PatrolStationModel> patrolStationModels = IService.findListQu(xdId);
        if (patrolStationModels != null && patrolStationModels.size() > 0) {
            for (PatrolStationModel patrolStationModel : patrolStationModels) {
                Map map = new HashMap();
                MapCordinatesVo cordinatesVo = new MapCordinatesVo();
                cordinatesVo.setLon(new BigDecimal(patrolStationModel.getLongitude()));
                cordinatesVo.setLat(new BigDecimal(patrolStationModel.getDimension()));
                cordinatesVo = CoordinatesConvertUtil.bd_encrypt(cordinatesVo);
                map.put("lt", cordinatesVo.getLon());//纬度
                map.put("ln", cordinatesVo.getLat());//经度
                map.put("type",patrolStationModel.getAreaType());
                map.put("lo", patrolStationModel.getLocation());
                List<Map> list=new ArrayList();

                if(null != patrolStationModel.getAreaType()){
                    if(patrolStationModel.getAreaType().equals("1")) {
                        Map map1 = new HashMap();
                        String text= patrolStationModel.getControlArea();
                        JSONObject stuInfoObj = JSONObject.parseObject(text);
                        String center = stuInfoObj.getString("center");
                        String radius = stuInfoObj.getString("radius");
                        JSONObject lnglatJson = JSONObject.parseObject(center);
                        String lt = lnglatJson.getString("lng");
                        String ln = lnglatJson.getString("lat");
                        map1.put("lt",lt);
                        map1.put("ln",ln);
                        map1.put("radius",radius);
                        list.add(map1);
                        System.out.println(lt + "---" + ln+"-------"+radius);
                    }else if(patrolStationModel.getAreaType().equals("2")){
                        list= JSON.parseArray(patrolStationModel.getControlArea(), Map.class);
                        list.remove(list.size()-1);
                        for(Map map1:list){
                            String latLng =map1.get("latLng").toString();
                            JSONObject stuInfoObj = JSONObject.parseObject(latLng);//先转换成JSONObject类型
                            String lt= stuInfoObj.getString("lng");
                            String ln= stuInfoObj.getString("lat");
                            System.out.println(lt+"---"+ln);
                            map1.put("lt",lt);
                            map1.put("ln",ln);
                        }
                    }else if(patrolStationModel.getAreaType().equals("3")){

                        list= JSON.parseArray(patrolStationModel.getControlArea(), Map.class);
                        list.remove(list.size()-1);
                        for(Map map1:list){
                            String latLng =map1.get("latLng").toString();
                            JSONObject stuInfoObj = JSONObject.parseObject(latLng);//先转换成JSONObject类型
                            String lt= stuInfoObj.getString("lng");
                            String ln= stuInfoObj.getString("lat");
                            System.out.println(lt+"---"+ln);
                            map1.put("lt",lt);
                            map1.put("ln",ln);
                        }
                    }
                }


                map.put("controlArea",list);//管控区域
                mapList.add(map);
            }
        }
        return ResultVo.success(mapList);
    }


    @Override
    public ResultVo<List<Map>> getListNew(String userId){
        List<Map> maps=new ArrayList<>();
        Map map = new HashMap();
        map.put("lt","1");
        map.put("ln","2");
        maps.add(map);
        return ResultVo.success(maps);


    }

    /**
    * 巡点管理 查询分页
    * @param pageNo 当前页
    * @param pageSize 每页条数
    * @param request request
    * @return ResultVo
    */
    @ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器")
    /*@RequiresPermissions("patrolstation_select")*/
    @Override
    public ResultVo<?> findPage(Integer pageNo, Integer pageSize, HttpServletRequest request){
        Map<String,String[]> queryMap = new LinkedHashMap(request.getParameterMap());
        queryMap.put("devid_EQ",new String[]{UserUtil.getSysUser().getCompanyId()});
        QueryBuilder<PatrolStation> queryBuilder = new WebQueryBuilder<>(entityClazz, queryMap);
        Page<PatrolStation, PatrolStationModel> page = new Page<>(pageNo, pageSize);
        page.setQueryWrapper(queryBuilder.build());
        page = IService.findPage(page);
        return ResultVo.success(page.getPageData());
    }

    @Override
    public ResultVo<?> findDevid(HttpServletRequest request) {
        String devid= UserUtil.getSysUser().getCompanyId();
        return ResultVo.success("公司id",devid);
    }


    @ApiOperation(value = "大屏调转巡点记录页面", notes = "大屏调转巡点记录页面 - 查询构造器")
    @Override
    public ResultVo<?> dpPsread(Integer pageNo, Integer pageSize, String housingName, HttpServletRequest request) {

        System.out.println(housingName);
        Map<String,String[]> queryMap = new LinkedHashMap(request.getParameterMap());
        queryMap.put("devid_EQ",new String[]{"41001"});
        queryMap.put("type_EQ",new String[]{"4"});
        queryMap.put("villageName_EQ",new String[]{housingName});
        QueryBuilder<PatrolStation> queryBuilder = new WebQueryBuilder<>(entityClazz, queryMap);
        Page<PatrolStation, PatrolStationModel> page = new Page<>(pageNo, pageSize);
        page.setQueryWrapper(queryBuilder.build());
        page = IService.findPage(page);

        return ResultVo.success(page.getPageData());
    }

    /**
    * 巡点管理 新增
    * @param model 模型
    * @return ResultVo
    */
    @ApiOperation(value = "新增巡点管理数据", notes = "新增巡点管理数据")
    @RequiresPermissions("patrolstation_insert")
    @EnableLog
    @Override
    public ResultVo<?> insert(PatrolStationModel model) {
        UserModel user = UserUtil.getSysUser();
        if(user!=null){
            model.setDevid(user.getCompanyId());
            model.setDevname(user.getCompany());
        }
//        WGS84转高德火星坐标系
//        double[] gpsCoUtils= GpsCoordinateUtils.calWGS84toGCJ02(Double.parseDouble(model.getDimension()),Double.parseDouble(model.getLongitude()));
//        Double n = gpsCoUtils[0];//经度
//        Double l = gpsCoUtils[1];//维度
//        model.setLongitude(l.toString());
//        model.setDimension(n.toString());
        try {
            MapCordinatesVo cordinatesVo=new MapCordinatesVo();
            cordinatesVo.setLon(new BigDecimal(model.getLongitude()));
            cordinatesVo.setLat(new BigDecimal(model.getDimension()));
            cordinatesVo= CoordinatesConvertUtil.gd_decrypt(cordinatesVo);
            model.setLongitude(cordinatesVo.getLon().toString());
            model.setDimension(cordinatesVo.getLat().toString());
        }catch (Exception e){

        }


        // 调用新增方法
        IService.insert(model);
        return ResultVo.success("新增巡点成功");
    }

    /**
    * 巡点管理 修改
    * @param model 模型
    * @return ResultVo
    */
    @ApiOperation(value = "修改巡点管理数据", notes = "修改巡点管理数据")
    @RequiresPermissions("patrolstation_update")
    @EnableLog
    @Override
    public ResultVo<?> update(PatrolStationModel model) {
        PatrolStationModel old=IService.get(model.getId());
        if(ZkUtils.isNotBlank(model.getDimension())&&ZkUtils.isNotBlank(model.getLongitude())){
            if(!model.getDimension().equals(old.getDimension())||!model.getLongitude().equals(old.getLongitude())){
                MapCordinatesVo cordinatesVo=new MapCordinatesVo();
                cordinatesVo.setLon(new BigDecimal(model.getLongitude()));
                cordinatesVo.setLat(new BigDecimal(model.getDimension()));
                cordinatesVo= CoordinatesConvertUtil.gd_decrypt(cordinatesVo);
                model.setLongitude(cordinatesVo.getLon().toString());
                model.setDimension(cordinatesVo.getLat().toString());
            }
        }
        // 调用修改方法
        IService.update(model);
        return ResultVo.success("修改巡点成功");
    }

    @Override
    public ResultVo<?> areaUpate(String id, String controlArea,String areaType ,HttpServletRequest request) {

        PatrolStationModel model =new PatrolStationModel();
        model.setId(id);
        if(areaType=="" || controlArea==""){
            IService.updateClear(id);
        }else {
            model.setAreaType(areaType);
            try {
                String data = java.net.URLDecoder.decode(controlArea, "UTF-8");
                model.setControlArea(data);
                IService.update(model);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return ResultVo.success("添加成功");
    }



    /**
    * 巡点管理 删除
    * @param id ID
    * @return ResultVo
    */
    @ApiOperation(value = "删除巡点管理数据", notes = "删除巡点管理数据")
    @RequiresPermissions("patrolstation_update")
    @EnableLog
    @Override
    public ResultVo<?> del(String id){
        IService.delete(id);
        return ResultVo.success("删除巡点成功");
    }

    /**
    * 巡点管理 批量删除
    * @param ids ID 数组
    * @return ResultVo
    */
    @ApiOperation(value = "批量删除巡点管理数据", notes = "批量删除巡点管理数据")
    @RequiresPermissions("patrolstation_update")
    @EnableLog
    @Override
    public ResultVo<?> delAll(String ids){
        String[] idArray = Convert.toStrArray(ids);
        IService.deleteAll(idArray);
        return ResultVo.success("批量删除巡点管理成功");
    }


    /**
    * 巡点管理 Excel 导出
    * 注：这里 RequiresPermissionsCus 引入的是 自定义鉴权注解
    *
    * 导出时，Token认证和方法权限认证 全部都由自定义完成
    * 因为在 导出不成功时，需要推送错误信息，
    * 前端直接走下载流，当失败时无法获得失败信息，即使前后端换一种方式后端推送二进制文件前端再次解析也是最少2倍的耗时
    * ，且如果数据量过大，前端进行渲染时直接会把浏览器卡死
    * 而直接开启socket接口推送显然是太过浪费资源了，所以目前采用Java最原始的手段
    * response 推送 javascript代码 alert 提示报错信息
    *
    * @param request request
    * @param response response
    */
    @ApiOperation(value = "导出Excel", notes = "导出Excel")
    @RequiresPermissionsCus("patrolstation_export")
    @EnableLog
    @Override
    public void exportExcel(HttpServletRequest request, HttpServletResponse response) {
        // 当前方法
        Method method = ReflectUtil.getMethodByName(this.getClass(), "exportExcel");
        QueryBuilder<PatrolStation> queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap());
        super.excelExport(PatrolStationRestApi.SUB_TITLE, queryBuilder.build(), response, method);
    }

    /**
    * 巡点管理 Excel 导入
    * 注：这里 RequiresPermissions 引入的是 Shiro原生鉴权注解
    * @param request 文件流 request
    * @return ResultVo
    */
    @ApiOperation(value = "导入Excel", notes = "导入Excel")
    @RequiresPermissions("patrolstation_import")
    @EnableLog
    @Override
    public ResultVo<?> importExcel(MultipartHttpServletRequest request) {
        return super.importExcel(request);
    }

    /**
    * 巡点管理 Excel 下载导入模版
    * 注：这里 RequiresPermissionsCus 引入的是 自定义鉴权注解
    * @param response response
    */
    @ApiOperation(value = "导出Excel模版", notes = "导出Excel模版")
    @RequiresPermissionsCus("patrolstation_import")
    @Override
    public void importTemplate(HttpServletResponse response) {
        // 当前方法
        Method method = ReflectUtil.getMethodByName(this.getClass(), "importTemplate");
        super.importTemplate(PatrolStationRestApi.SUB_TITLE, response, method);
    }

    @Override
    public void getImages(HttpServletRequest request,HttpServletResponse response){
        InputStream fis = null;
        OutputStream os = null ;
        URL url = null;
        HttpURLConnection httpUrl = null;
        String path = request.getParameter("path");
        try {
            fis = new FileInputStream(path);
            os = response.getOutputStream();
            int count = 0;
            byte[] buffer = new byte[1024 * 8];
            while ((count = fis.read(buffer)) != -1) {
                os.write(buffer, 0, count);
                os.flush();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fis.close();
                os.close();
//                httpUrl.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}
